﻿using ImGuiNET;
using OpenTK.Graphics.OpenGL4;

namespace TrinityEngine.SceneManagement
{
    public static class SceneManager
    {
        private static List<SceneBuilder> _sceneList = new() { new SpriteBatcherTestScene(), new SimpleSpriteRendererTestScene() };

        private static int _index = 0;

        private static Scene _currentScene;

        public static int sceneCount
        {
            get { return _sceneList.Count; }
        }

        public static Scene GetActiveScene()
        {
            return _currentScene;
        }

        public static void LoadScene(int index)
        {
            _index = index;
            _currentScene?.UnLoad();
            _currentScene = _sceneList[_index].Build();
            GL.ClearColor(_currentScene.Camera.background);
            Camera.main = _currentScene.Camera;
        }

        public static void ShowDebugMenu()
        {
            for (int i = 0; i < _sceneList.Count; i++)
            {
                if (ImGui.Button(_sceneList[i].ToString()))
                {
                    LoadScene(i);
                }
            }
        }

        public static void OnUnload()
        {
            for (int i = 0; i < _sceneList.Count; i++)
            {
                _sceneList[i].Dispose();
            }
        }
    }
}
